package cn.observer2;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jt on 2018/3/22.
 */
public class Radio implements Observable {
    //用来存放所有的观察者
    private List<Observer> observers = new ArrayList<>() ;
    @Override
    public void addObserver(Observer observer) {
        this.observers.add(observer) ;
    }

    @Override
    public void deleteObserver(Observer observer) {
        this.observers.remove(observer) ;
    }

    @Override
    public void notifyObserver(String msg) {
        for(Observer observer : observers){
            observer.update(msg) ;
        }
    }
    public void music(){
        System.out.println("收音机开始播放音乐");
        this.notifyObserver("播放音乐");
    }

    public void news(){
        System.out.println("收音机播放新闻");
        this.notifyObserver("播放新闻");
    }
}
